<template>
  <svg
    :class="svgClass"
    :style="{ width: size, height: size, color }"
    aria-hidden="true"
  >
    <use :xlink:href="symbolId" :fill="color" />
  </svg>
</template>

<script setup lang="ts" name="SvgIcon">
import { computed } from 'vue';

const props = defineProps({
  /** 图标名称 */
  name: { type: String, required: true },
  /** 图标大小
   * @description 支持px/em单位
   */
  size: { type: String, default: '1em' },
  /** 颜色 */
  color: { type: String, default: 'currentColor' },
  /** 自定义类名 */
  className: String,
});

const symbolId = computed(() => `#icon-${props.name}`);
const svgClass = computed(() =>
  props.className ? `svg-icon ${props.className}` : 'svg-icon',
);
</script>

<style scoped>
.svg-icon {
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
